import pyttsx3
from bs4 import BeautifulSoup
import requests


def downHTML(url):

    try:
        html = requests.get(url)
        code200 = html.raise_for_status()
        print(code200)
        html.encoding = 'utf-8'
        return html.text
    except:
        print("失败")



html = downHTML("https://sspai.com/")

soup = BeautifulSoup(html)

engine = pyttsx3.init()


for aa in soup.find_all("div", class_="content text_ellipsis2"):
    str3 = str(aa.contents)


    start = str3.find("n")
    end = str3.rfind("\\")

    print(str3[start + 1:end])


    engine.say(str3[start + 1:end])
    engine.runAndWait()
